/**
 * @author tongchen
 * @create 2023-02-01 21:03
 */
public class FindOnlyNum2 {
    public static void main(String[] args) {
        //创建数组
        int[]nums={1,1,1,2,2,2,3,3,3,4};
        int frequency=3;
        int maxSize=0;
        char[][]twoDemision=new char[nums.length][];
        //转化为三进制
        for (int i = 0; i < nums.length ; i++) {
            twoDemision[i]=new StringBuilder(Integer.toString(nums[i],frequency)).reverse().toString().toCharArray();
        }
        //寻找每个数组中的最大位数
        for (int i = 0; i <nums.length ; i++) {
            if(twoDemision[i].length>maxSize){
                maxSize=twoDemision[i].length;
            }
        }
        //创建新的一维数组进行存储
        int[]resArr=new int[maxSize];
        //二维数组存取
        for (int i = 0; i < nums.length ; i++) {
            for (int j = 0; j < maxSize; j++) {
                if(j>=twoDemision[i].length){
                    resArr[j]+=0;
                }
                else {
                    resArr[j]+=twoDemision[i][j]-'0';
                }
            }

        }
        int res=0;
        //最后处理resArr
        for (int j = 0; j < maxSize; j++) {
            res+=resArr[j]%frequency*(int) Math.pow(frequency,j);
        }
        System.out.println(res);
    }
}
